package com.turnengine.client.local.location.plugin.generation;

import java.util.ArrayList;
import java.util.List;

import com.turnengine.client.local.location.bean.GeneratedLocation;
import com.turnengine.client.local.location.bean.IGeneratedLocation;
import com.turnengine.client.local.location.enums.LocationSignup;
import com.turnengine.client.local.unit.bean.IUnitCount;

/**
 * Basic implementation which takes a number of locations and list of units for each location.
 */
public class LocationGenerationPlugin implements ILocationGenerationPlugin {

	private final int locations;
	private final int signupFactionId;
	private final List<IUnitCount> unitList;

	public LocationGenerationPlugin(int locations, int signupFactionId, List<IUnitCount> unitList) {
		if (locations < 1) {
			throw new IllegalArgumentException("locations=" + locations);
		}
		if (unitList == null) {
			throw new NullPointerException("unitList");
		}
		this.locations = locations;
		this.signupFactionId = signupFactionId;
		this.unitList = unitList;
	}

	@Override
	public List<IGeneratedLocation> generateLocations() {
		List<IGeneratedLocation> locationList = new ArrayList<IGeneratedLocation>();
		for (int i = 0; i < locations; i++) {
			GeneratedLocation location = new GeneratedLocation(LocationSignup.SIGNUP, signupFactionId, unitList);
			locationList.add(location);
		}
		return locationList;
	}

}
